export default {
	state: {
		loginStatus: false,
		token: null,
		userInfo: {}
	},
	getters: {
		getUserInfo: state => {
			return state.userInfo
		}
	},
	mutations: {
		//进入软件之后，读取用户信息
		//这玩意要放在APP.vue里面去的~
		initUser(state) {
			let userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				userInfo = JSON.parse(userInfo);
				// console.log(userInfo);
				state.userInfo = userInfo;
				state.loginStatus = true;
				state.token = userInfo.token;
			}
		},

		//登录之后保存用户信息
		updateUser(state, userData) {
			state.userInfo = userData;
			state.loginStatus = true;
			state.token = userData.token;
			console.log(userData);
			//存储到本地
			uni.setStorageSync('userInfo', JSON.stringify(userData))
		},

		//更新用户的数据
		uodataUserInfo(state, userData) {
			state.userInfo = {
				...state.userInfo,
				...userData
			}
		},
		//退出登录
		loginOut(state) {
			state.loginStatus = false;
			state.userInfo = {};
			state.token = null;
			uni.removeStorageSync('userInfo');
		}
	},
	actions: {}
}